//
//  FamilyManageThreeCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/29.
//  Copyright © 2020 tym. All rights reserved.
//

#import "FamilyManageThreeCell.h"
#import "Masonry.h"
#import "Colors.h"
#import "Sizes.h"
#import "UIImageView+YPImage.h"
#import "UIView+ZFFrame.h"
#import "Fonts.h"
#import "TYMLabel.h"
#import "TYMButton.h"

@interface FamilyManageThreeCell()

@property(nonatomic,weak) TYMLabel *sectionLab;
@property(nonatomic,weak) UIView *lineView;

@property(nonatomic,weak) UIView *conView;
@property(nonatomic,weak) UIImageView *headImage;
@property(nonatomic,weak) UIImageView *mobImage;
@property(nonatomic,weak) TYMLabel*titLab;
@property(nonatomic,weak) TYMLabel *conLab;
@property(nonatomic,weak) UIImageView *rightImage;


@end

@implementation FamilyManageThreeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    self.backgroundColor = [UIColor whiteColor];
    
    TYMLabel *sctLab = [TYMLabel lb_text:@"家庭成员" font:Font_Regular(15) color:rgba(155, 155, 155)];
    sctLab.frame = CGRectMake(15, 0, 200, 44);
    [self.contentView addSubview:sctLab];
    self.sectionLab = sctLab;
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth- 30 , 1)];
    line.backgroundColor = rgba(242, 242, 242);
    [self.contentView addSubview:line];
    self.lineView = line;
    
    UIView *conView = [[UIView alloc] initWithFrame:CGRectMake(0, 54, ScreenWidth - 30, 70)];
    conView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:conView];
    self.conView = conView;
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_home3"]];
    image.frame = CGRectMake(15, 7.5, 30, 30);
    image.contentMode = UIViewContentModeScaleAspectFill;
    image.layer.masksToBounds = YES;
    image.layer.cornerRadius = 15;
    [self.conView addSubview:image];
    self.headImage = image;
    
    UIImageView *mobImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tag_phone"]];
       mobImage.frame = CGRectMake(30, 25, 17, 17);
       [self.conView addSubview:mobImage];
       self.mobImage = mobImage;
    
    TYMLabel *titLab = [TYMLabel lb_text:@"家庭成员" font:Font_Medium(15) color:rgba(74, 74, 74)];
    titLab.frame = CGRectMake(50, 10, 150, 21 );
    [self.conView addSubview:titLab];
    self.titLab = titLab;
    
    UIImageView *righimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_list_more"]];
    righimage.frame = CGRectMake(ScreenWidth - 40-18, 11.5, 18, 18);
    [self.conView addSubview:righimage];
    self.rightImage = righimage;
    
   
    
    TYMLabel *lab = [TYMLabel lb_text:@"内容" font:Font_Regular(15) color:rgba(155, 155, 155)];
    lab.textAlignment = NSTextAlignmentRight;
    lab.frame = CGRectMake(ScreenWidth - 18- 40 - 160, 10, 160, 21);
    [self.conView addSubview:lab];
    self.conLab = lab;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth - 15-30, 1)];
    view.backgroundColor = rgba(221, 221, 221);
    view.hidden = YES;
    [self.conView addSubview:view];
    self.lineV = view;
}

-(void)setUserModel:(UserModel *)userModel{
    if (userModel.nickname.length) {
        self.titLab.text = userModel.nickname;
    }else {
        self.titLab.text = userModel.mobile;
    }
    
    
    self.conLab.text = [userModel getRoleStr];
    if (userModel.familyRole == 1) {
        self.conLab.textColor = rgba(76, 132, 255);
        self.conLab.font = Font_Medium(15);
        self.headImage.layer.borderWidth = 1.5;
        self.headImage.layer.borderColor = rgba(76, 132, 255).CGColor;
    }else{
        self.conLab.textColor = rgba(155, 155, 155);
        self.conLab.font = Font_Regular(15);
    }
    
    if (userModel.headImgUrl.length) {
        [self.headImage yp_setImageUlr:[userModel getEquipmentImage]];
    }
    
    if(userModel.type == 1){
        self.mobImage.hidden = NO;
    }else{
        self.mobImage.hidden = YES;
    }
}

-(void)hiddenSectionView{
    self.sectionLab.hidden = YES;
    self.lineView.hidden = YES;
    
    self.conView.frame = CGRectMake(0, 0, ScreenWidth - 30, 45);
}

-(void)showSectionView{
    self.sectionLab.hidden = NO;
    self.lineView.hidden = NO;
    
    self.conView.frame = CGRectMake(0,54, ScreenWidth - 30, 45);
}

+(NSString*)identifier{
    return @"FamilyManageThreeCell";
}

+(CGFloat)cellForHeight{
    return 45;
}
@end
